package com.example.demo.controller;


import com.example.demo.pojo.Course;
import com.example.demo.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CourseController {

    @Autowired
    private CourseService courseService;

    @RequestMapping(value = "queryCourse" ,method = RequestMethod.POST)
    public List<Course> queryCourse(){
        return courseService.queryCourse();
    }

    @RequestMapping(value = "addCourse",method = RequestMethod.POST)
    public String addCourse(String course_name,Integer teacher_id,Integer classes_id){
        if (course_name==""||teacher_id.equals(null)||classes_id.equals(null))
        {
            return "不能为空";
        }
        else{
            courseService.addCourse(course_name,teacher_id,classes_id);
            return "增加课程成功";
        }

    }
    @RequestMapping(value = "updateCourse",method = RequestMethod.POST)
    public String updateCourse(Course course)
    {
        if (course==null){
            return "不为空";
        }
        else {
            courseService.updateCourse(course);
            return "修改成功";
        }
    }
    @RequestMapping(value = "deleteCourse",method = RequestMethod.POST)
    public String deleteCourse(Integer id)
    {
        if (id!=null){
            courseService.deleteCourse(id);
            return "删除成功";
        }
        else {
            return "删除失败";
        }
    }
}
